//
//  HomePageController.m
//  WashForU
//
//  Created by 王俊 on 15/11/25.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "HomePageController.h"

@interface HomePageController ()

@end

@implementation HomePageController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self customViewSetUp];
    [self customConstrainsAdd];
    [self targetAdd];
}
/*****************添加视图组件********************/
- (void)customViewSetUp
{
    self.backButton.hidden = true;
    self.titleLabel.hidden = true;

    _titleImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"主页标题"]];
    [self.view addSubview:_titleImage];
    
    _topScrollView                                = [[UIScrollView alloc]init];
    _topScrollView.contentSize                    = CGSizeMake(SCREENWIDTH, 130);
    _topScrollView.showsHorizontalScrollIndicator = false;
    _topScrollView.showsVerticalScrollIndicator   = false;
    _topScrollView.pagingEnabled                  = true;
    _topScrollView.delegate                       = self;
    _topScrollView.backgroundColor                = [ UIColor redColor];
    [self.view addSubview:_topScrollView];
    
    _caseWashButton      = [[UIButton alloc]init];
    _bagWashButton       = [[UIButton alloc]init];
    _furnitureWashButton = [[UIButton alloc]init];
    _elseWashButton      = [[UIButton alloc]init];
    _serverInfoButton    = [[UIButton alloc]init];
    
    [self buttonSetUp:_caseWashButton      imageName:@"件洗"];
    [self buttonSetUp:_bagWashButton       imageName:@"袋洗"];
    [self buttonSetUp:_furnitureWashButton imageName:@"家居用品"];
    [self buttonSetUp:_elseWashButton      imageName:@"其它洗护"];
    [self buttonSetUp:_serverInfoButton    imageName:@"服务说明"];
    
    
    
}
/*******************添加约束**********************/
- (void)customConstrainsAdd
{
    [_titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(78);
        make.height.mas_equalTo(18);
        make.centerX.equalTo(self.upView);
        make.centerY.equalTo(self.upView).offset(5);
    }];
    [_topScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.upView.mas_bottom);
        make.leading.trailing.equalTo(self.view);
        make.height.mas_equalTo(130);
    }];
    [_caseWashButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.view).offset(15);
        make.width.mas_equalTo(SCREENWIDTH/2 - 20);
        make.top.equalTo(self.topScrollView.mas_bottom).offset(10);
        make.height.mas_equalTo((SCREENWIDTH/2 - 25)*4/7);
    }];
    [_bagWashButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.width.height.equalTo(self.caseWashButton);
        make.trailing.equalTo(self.view).offset(-15);
    }];
    [_furnitureWashButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bagWashButton.mas_bottom).offset(10);
        make.leading.equalTo(self.caseWashButton);
        make.trailing.equalTo(self.bagWashButton);
        make.height.mas_equalTo((SCREENWIDTH - 30)*130/580);
    }];
    [_elseWashButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.equalTo(self.furnitureWashButton);
        make.top.equalTo(self.furnitureWashButton.mas_bottom).offset(10);
    }];
    [_serverInfoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.equalTo(self.furnitureWashButton);
        make.top.equalTo(self.elseWashButton.mas_bottom).offset(10);
    }];
}
/*******************添加事件**********************/
- (void)targetAdd
{
    [_caseWashButton addTarget:self action:@selector(caseWashButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [_bagWashButton addTarget:self action:@selector(bagWashButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.serverInfoButton addTarget:self action:@selector(serverInfoButtonClicked) forControlEvents:UIControlEventTouchUpInside];
}
/*********************设置Button格式************************/
- (void)buttonSetUp:(UIButton*) button imageName:(NSString*) imageName
{
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [self.view addSubview:button];
}
- (void)caseWashButtonClicked
{
    CaseWashPageController *vc = [[CaseWashPageController alloc]init];
    [self.navigationController pushViewController:vc animated:true];
}
- (void)serverInfoButtonClicked
{
    ServiceRangePageController *vc = [[ServiceRangePageController alloc]init];
    [self.navigationController pushViewController:vc animated:true];
}
- (void)bagWashButtonClicked
{
    ClothesInfo *data = [ClothesInfo initWithTitle:@"袋洗" andImageName:@"袋洗图片" andPrice:68];
    ClothesInfo *data2 = [ClothesInfo initWithTitle:@"袋洗" andImageName:@"袋洗图片" andPrice:68 andDescInfo:@"装多少，洗多少！\n\n亲，皮衣、真丝内衣、袜子、鞋不要装哦！"];

    [PopUpView show:data2];
    
}

@end
